﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BusTraffic
{
    class UpdateDaemon
    {
        UpdateDaemon theDaemon;
        int[] routes = { 44, 16, 545 };
        const int UpdateInterval = 60000; // ms
        System.Threading.Thread thread;

        public UpdateDaemon()
        {
            thread = new System.Threading.Thread(UpdateThread);
            theDaemon = this;
            thread.Start();
        }

        internal void UpdateRoute(int routeNum)
        {
            BusLib.Route route = BusLib.Route.GetRouteByNumber(routeNum);
            route.Update();
        }

        void UpdateThread()
        {
            while (true)
            {
                foreach (int routeNum in routes)
                {
                    UpdateRoute(routeNum);
                }
                System.Threading.Thread.Sleep(UpdateInterval);
            }
        }
    }
}
